package model.tokens;

import java.util.Deque;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;

import model.parser.FunctionTable;
import model.parser.Parser;
import model.semantics.Node;

/**
 * Function tokens are all the different functions that we have (plus, minus,
 * perlinColor, etc).
 */

public class FunctionToken<T> extends FunctionalToken<T> {

    public FunctionToken(TokenConstructorArguments<T> args) {
        super(args);
    }

    @Override
    public void process(Automaton<T> state) {
        shuntFunctionsToOutput(state.operatorStack, state.output);

        Automaton<T> inner = state.makeBlankAutomaton();
        inner.processTokens();
        Node<T> instance = makeNewInstance(inner.output);
        state.output.add(instance);
        state.merge(inner);

        shuntFunctionsToOutput(state.operatorStack, state.output);
    }

    @Override
    public Node<T> makeNewInstance(Deque<Node<T>> queue) {
        return myFunctionDefinition.makeNewInstance(queue, true);
    }

}
